﻿using B.S.BasicData.Api.Read.Application.Command.Menu;
using B.S.BasicData.Api.Read.Application.Command.RoleMenu;
using B.S.BasicData.Domian.Entities.Menu;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interface;
using MediatR;

namespace B.S.BasicData.Api.Read.Application.Handler.RoleMenu
{
    public class GetMenuidHandler : IRequestHandler<GetMenuidCommand, ApiResult<List<int>>>
    {
        private readonly IBaseRepository<RoleMenuModel> rolemenuRepo;

        public GetMenuidHandler(IBaseRepository<RoleMenuModel> rolemenuRepo)
        {
            this.rolemenuRepo = rolemenuRepo;
        }
        public Task<ApiResult<List<int>>> Handle(GetMenuidCommand request, CancellationToken cancellationToken)
        {
            var res = new ApiResult<List<int> > ();
            List<int> menuid = rolemenuRepo.GetAll().Where(x => x.Rid == request.RoleId).Select(x => x.Mid).ToList();
            res.Data = menuid;
            res.Message = "反填成功";
            res.Code = ApiEnum.Ok;
            return Task.FromResult(res);
        }
    }
}
